#ifndef _SCENE_H_
#define _SCENE_H_

#include <stdio.h>
#include "../ExEngine/common/hashtable.hpp"
#include "../ExEngine/common/arraylist.hpp"

#include "../ExEngine/render/interface_types.h"

extern HRESULT LoadDemo(); 
extern HRESULT ShutdownDemo(); 
extern HRESULT UpdateDemo(const float dt); 

class TrafficLight
{
private:
	CObject* pModel;
	D3DLight* pLight;
	D3DSprite* pFlare;
	D3DSprite* pLenseFlareA;
	float mDuration;
public:

	TrafficLight();
	~TrafficLight();

	HRESULT Create();
	void Update(float dt);
	void Draw();
	HRESULT Release();
	void SetPosition(const Vector3f& positon);
	Vector3f GetPosition();
};

class TunnelSegement
{
private:
	CObject* pModel;
	CObject** pPropModels;
	unsigned int mPropCount;
public:
	TunnelSegement();
	HRESULT Create(const Vector3f &position);
	void Update(float dt);
	void Draw();
	Vector3f GetPosition();
	HRESULT Release();
};

class TunnelLight
{
private:
	COLOR3F mColor;
	CObject* pModel;
	D3DLight* pLight;
	D3DSprite* pFlare;

public:
	TunnelLight();
	HRESULT Create();
	void Update(float dt);
	void Draw();
	HRESULT Release();
	void SetPosition(const Vector3f& position);
	void SetVisiblity(const float value);
	Vector3f GetPosition();
};

#define SPAWN_TRAFFICLIGHT_THRESHOLD 250.0f
#define TRAFFICLIGHT_COUNT 2


class TunnelLightManager
{
private:
	
	ArrayList<TrafficLight*> mTrafficLights;
	ArrayList<TunnelLight*> mLeftLights;
	ArrayList<TunnelLight*> mRightLights;
	Vector3f mCameraLastPosition;

public:
	TunnelLightManager();
	HRESULT Create();
	void Update(float dt);
	void Draw();
	HRESULT Release();
};

class Train
{
private:
	const unsigned int HEADLIGHT_COUNT;
	CObject** pCarraiges;
	D3DLight** pCarraigeLights;
	unsigned int m_CarraigeCount;
	D3DLight* pHeadLights[2];
	D3DSprite* pHeadLightLensEffects[2];
	Vector3f m_MidPoint;
	float m_Phase;
	float m_Velocity;
public:

	Train();

	HRESULT Create(unsigned int carraigeCount);
	void Update(float dt);
	void Draw();
	HRESULT Release();
	void SetMidpoint(const Vector3f& midpoint);
	void SetVelocity(const float velocity);
};


extern const int TUNNEL_RANGE;
extern Train g_train;
extern const int g_tunnelSegments;
extern HashTable<TunnelSegement*,int> g_tunnel;
extern TunnelLightManager lightManager;
extern const bool SHOW_TRAINS;
extern const bool SHOW_PROPS;


#endif